package com.teziyou.commodity.logic;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.mytravel.platform.bean.AdministrativeBean;
import com.teziyou.commodity.service.AreaService;
import com.teziyou.commodity.util.Maps;

@SuppressWarnings("rawtypes")
@Service
public class AreaLogic {

	@Autowired
	private AreaService areaService;
	
	public String addAndUpdateDivision(int id, int parentDivisionID,
			String name, String capitalCityName, double GPSLat, double GPSLng,
			int itemValue) {
		return areaService.addAndUpdateDivision(id, parentDivisionID, name, capitalCityName,
				GPSLat, GPSLng, itemValue);
	}

	public AdministrativeBean getAdministrativeById(int divisionID) {
		return areaService.getAdministrativeById(divisionID);
	}

	public List<AdministrativeBean> getAdministrativeListByLevel(
			int parentDivisionID, int itemLevel, int itemValue) {
		return areaService.getAdministrativeListByLevel(parentDivisionID, itemLevel,
				itemValue);
	}

	public List<AdministrativeBean> getAdministrativeListByPid(
			int parentDivisionID, int itemValue) {
		return areaService.getAdministrativeListByPid(parentDivisionID, itemValue);
	}

	public String queryAllForPid(int parentDivisionID, int itemValue) {
		return areaService.queryAllForPid(parentDivisionID, itemValue);
	}

	public String queryByItemLevel(int parentDivisionID, int itemLevel,
			int itemValue) {
		return areaService.queryByItemLevel(parentDivisionID, itemLevel, itemValue);
	}

	public String queryOneForDivision(int divisionID, int itemValue) {
		return areaService.queryOneForDivision(divisionID, itemValue);
	}

	public String queryOneForDivisionByName(String name, int itemValue) {
		return areaService.queryOneForDivisionByName(name, itemValue);
	}

	public String queryTree(int parentDivisionID, int itemValue) {
		return areaService.queryTree(parentDivisionID, itemValue);
	}
	
	public Map getParentMapByDistrictId(int districtId) {
		AdministrativeBean district = areaService.getAdministrativeById(districtId);
		int cityId = district.getParentDivisionID();
		System.out.println(cityId);
		List districts = areaService.getAdministrativeListByPid(cityId, -1);
		AdministrativeBean city = areaService.getAdministrativeById(cityId);
		int provinceId = city.getParentDivisionID();
		System.out.println(provinceId);
		List citys = areaService.getAdministrativeListByPid(provinceId, -1);
		return Maps.newHashMap("citys", citys, "districts", districts, "cityId", cityId, "provinceId", provinceId);
	}
	
}
